function addUserInstitution() {
	window.location.href = 'addUserInstitution.jsp';
}

function editInstitution() {
	window.location.href = 'reviseUserInstitution.jsp';

}
var institutionId = sessionStorage.getItem("institutionId") || 1;

function deleteInstitution() {
	var params = {
		userId: $.Cookie("userId"),
		session: $.Cookie("session"),
		id: institutionId,
		flag: "1"
	}
	$.ajax({
		url: 'orgOperation',
		type: 'POST',
		data: params,
		dataType: 'json',
		success: function(data) {
			if(data.errorCode == 0) {
				sessionStorage.setItem("institutionId", '1');
				parent.location.href = 'userInstitution.jsp';
			} else if(data.errorCode == -6) {
				alert("登录超时！")
				top.location.href = 'index.jsp';

			} else {
				alert("请重试！")
			}
		},
		error: function(err) {
			alert("连接服务器失败！请重新提交！");
			top.location.href = 'index.jsp';

		}
	});
}

var param = {
	userId: $.Cookie("userId"),
	session: $.Cookie("session"),
	id: institutionId,
}

$.ajax({
	url: 'getOrgById',
	type: 'POST',
	data: param,
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == -303) {
			alert("机构不存在！")
		} else if(data.errorCode == -6) {
			alert("登陆超时！")
			top.location.href = 'index.jsp';

		} else if(data.errorCode == 0) {
			$("#orgName").text(data.result.orgName);
			$("#orgType").text(data.result.orgType);
			$("#orgId").text(data.result.orgId);
			$("#principal").text(data.result.principal);
			$("#phone").text(data.result.phone);
			if(data.result.province.replace(/(^s*)|(s*$)/g, "").length == 0) {
				if(data.result.city.replace(/(^s*)|(s*$)/g, "").length == 0) {
					if(data.result.area.replace(/(^s*)|(s*$)/g, "").length == 0) {
						address = data.result.address
						$("#address").text(address);
					} else {
						address = data.result.area + "区" + data.result.address
						$("#address").text(address);
					}
				} else if(!data.result.city.replace(/(^s*)|(s*$)/g, "").length == 0) {
					if(data.result.area.replace(/(^s*)|(s*$)/g, "").length == 0) {
						address = data.result.city + "市" + data.result.address;
						$("#address").text(address);
					} else {
						address = data.result.city + "市" + data.result.area + "区" + data.result.address;
						$("#address").text(address);
					}
				}
			} else if(!data.result.province.replace(/(^s*)|(s*$)/g, "").length == 0) {
				if(data.result.city.replace(/(^s*)|(s*$)/g, "").length == 0) {
					if(data.result.area.replace(/(^s*)|(s*$)/g, "").length == 0) {
						address = data.result.province + "省" + data.result.address
						$("#address").text(address);
					} else {
						address = data.result.province + "省" + data.result.area + "区" + data.result.address
						$("#address").text(address);
					}
				} else if(!data.result.city.replace(/(^s*)|(s*$)/g, "").length == 0) {
					if(data.result.area.replace(/(^s*)|(s*$)/g, "").length == 0) {
						address = data.result.province + "省" + data.result.city + "市" + data.result.address;
						$("#address").text(address);
					} else {
						address = data.result.province + "省" + data.result.city + "市" + data.result.area + "区" + data.result.address;
						$("#address").text(address);
					}
				}
			}
			if(data.result.createdTime == null) {

			} else {
				var nDate = new Date(data.result.createdTime); //直接将毫秒数当参数传进去。
				var month = nDate.getMonth() + 1;
				var year = nDate.getFullYear() + '-' + month + '-' + nDate.getDate() + " " + nDate.getHours() + ':' + nDate.getMinutes() + ':' + nDate.getSeconds();
				$("#createdTime").text(year);

			}
			if(data.result.updatedTime == null) {

			} else {
				var nnDate = new Date(data.result.updatedTime); //直接将毫秒数当参数传进去。
				var nmonth = nnDate.getMonth() + 1;
				var nyear = nnDate.getFullYear() + '-' + nmonth + '-' + nnDate.getDate() + " " + nnDate.getHours() + ':' + nnDate.getMinutes() + ':' + nnDate.getSeconds();
				$("#updatedTime").text(nyear);

			}

			$("#createdBy").text(data.result.createdBy);

			$("#updatedBy").text(data.result.updatedBy);

		}

	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！")
		top.location.href = 'index.jsp';
	}
});